package se.sudoku;

import android.app.Activity;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;


public class SudokuPausMenu extends Activity {

	//SUDOKUMENU ITEMS
	private PopupWindow pausmenu;
	private Button pausmenu_btn_1, pausmenu_btn_2, pausmenu_btn_3;
	private Activity activity;
	
	//constructor
	public SudokuPausMenu(Context c) {
		activity = (Activity) c;
		//popup window
		pausmenu = new PopupWindow(View.inflate(c, R.layout.sudokupausmenu, null), LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, true);	    
		pausmenu.setAnimationStyle(R.style.anim_fade);
		//buttons here
		pausmenu_btn_1 = (Button)pausmenu.getContentView().findViewById(R.id.sudokupausmenu_btn1);
		pausmenu_btn_1.setOnClickListener(sudukoPausListener);
	    pausmenu_btn_2 = (Button)pausmenu.getContentView().findViewById(R.id.sudokupausmenu_btn2);
	    pausmenu_btn_2.setOnClickListener(sudukoPausListener);
	    pausmenu_btn_3 = (Button)pausmenu.getContentView().findViewById(R.id.sudokupausmenu_btn3);
	    pausmenu_btn_3.setOnClickListener(sudukoPausListener);
	}
	
	//toggle windows
	public void togglePausWindow(){  	
    	if(!pausmenu.isShowing()){
    		pausmenu.showAtLocation(activity.findViewById(R.id.sudokuview), Gravity.CENTER, 0, 0);
    	}
    	else{
    		pausmenu.dismiss();
    	}
    }
	
	//SUDOKU MENU CLICK LISTENERS
	private OnClickListener sudukoPausListener = new OnClickListener() {
		public void onClick(View v) {
			
			//resume
			if(v==pausmenu_btn_1){
				togglePausWindow();
			}
			//main menu
			else if(v==pausmenu_btn_2){
				//quit game
				togglePausWindow();
				activity.setResult(RESULT_CANCELED);
				activity.finish();
			}
			//quit
			else if(v==pausmenu_btn_3){
				togglePausWindow();
				activity.setResult(RESULT_OK);
				activity.finish();
			}
	    	
	    }
	};
	
	
}